/*
 * AGENT SHERPA
 *  
 * Assignement 2 of the Agent Oriented Software Engineering Course
 * M.Sc. in Advanced Software Engineering (Part-time)
 * University College Dublin www.ucd.ie
 *
 * Copyright (c) 2007 Chris Walsh, Aidan Morrisy and Iain Hull.
 * All rights reserved.
 * 
 * Filename: Main.aps
 * Author:   iain
 * Date:     06 February 2008
 */

package org.agentsherpa.scratch;

import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.IOException;
import java.text.MessageFormat;

import javax.imageio.ImageIO;

import org.agentsherpa.model.GlobalMap;

public class ReadBitmap {
    public static void main(String[] args) throws IOException {
        BufferedImage img = ImageIO.read(GlobalMap.class
                .getResource("faluja_mask.png"));
        Raster raster = img.getData();

        System.out.println(img.getType() + " " + BufferedImage.TYPE_CUSTOM);
        System.out.println(raster.getNumBands());
        System.out.println(raster.getHeight() + " " + raster.getWidth());

        int[] samples = new int[raster.getNumBands()];

        for (int i = 0; i < raster.getWidth(); ++i) {
            for (int j = 0; j < raster.getHeight(); ++j) {
                raster.getPixel(i, j, samples);
                
                if (testSamples(samples)) {
                    System.out.print(MessageFormat.format("{0,number,000} {1,number,000} :", i, j)); 
                    printSamples(samples);
                    System.out.print("   ");
                }
            }
            System.out.println();
        }
    }

    private static void printSamples(int[] samples) {
        for(int i : samples) {
            System.out.print(MessageFormat.format("{0,number,000} ", i));
        }
    }

    private static boolean testSamples(int[] samples) {
        for(int i : samples) {
            if (i != 0) {
                return true;
            }
        }
        return false;
    }

}
